/**
 * Equality.java
 * 
 * Copyright (C) 2012 - Thibault BUREL
 * 
 * This file is part of MathDraft.
 *
 * MathDraft is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MathDraft is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MathDraft.  If not, see <http://www.gnu.org/licenses/>
 *  
 */
package drk.mathdraft.proposition;


public class Equality extends BinaryOperation
{
	/*************************************************************************
	 *                        C O N S T A N T S                              *
	 *************************************************************************/
	private final static String SYMBOL   = new String("=");
	private final static int    PRIORITY = 1;
	
	/*************************************************************************
	 *                          M E T H O D S                                *
	 *************************************************************************/	
	public Equality()
	{
		super(SYMBOL, PRIORITY);
	}
	
	public Equality(Equality e)
	{
		super(e);
	}
	
	public Equality (Proposition l, Proposition r)
	{
		super(SYMBOL, PRIORITY, l, r);
	}
	
	public void addSameExpEachMembers (Proposition e)
	{
		// The copy of the child will be performed in the constructor
		Plus new_left  = new Plus(this.getFirst() , e);
		Plus new_right = new Plus(this.getSecond(), e);
		
		this.setFirst (new_left);
		this.setSecond(new_right);
	}
	
	public boolean equals(Proposition p)
	{
		if(p instanceof Equality)
		{
			if(this.getFirst().equals(((Equality)p).getFirst()) &&
			   this.getSecond().equals(((Equality)p).getSecond()))
			{
				return true;
			}
			
			if(this.getFirst().equals(((Equality)p).getSecond()) &&
			   this.getSecond().equals(((Equality)p).getFirst()))
			{
				return true;
			}
		}
		return false;
	}
	
	public void mulSameExpEachMembers (Proposition e)
	{
		// The copy of the child will be performed in the constructor
		Multiplication new_left  = new Multiplication(this.getFirst() , e);
		Multiplication new_right = new Multiplication(this.getSecond(), e);
		
		this.setFirst (new_left);
		this.setSecond(new_right);
	}
	
	public Proposition copy()
	{
		return new Equality(this);
	}
	
	public String getIconCommand()
	{
		return "=";
	}
}